<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" 
	import="java.util.List,java.util.ArrayList,com.telecom.cms.dao.*,com.telecom.cms.dto.*" %>
<jsp:directive.page import="com.telecom.tree.TreeUtil"/>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
	if (session.getAttribute("curTemplate") != null && request.getAttribute("idaTemplate") != null){
		request.setAttribute("idaTemplate", session.getAttribute("curTemplate"));
	}
	String foldId = "0";
	if (request.getAttribute("idaTemplate") != null)
		foldId = String.valueOf(((IdaTemplate)request.getAttribute("idaTemplate")).getFolderId());
	if (session.getAttribute("curTemplate") != null)
		foldId = String.valueOf(((IdaTemplate)session.getAttribute("curTemplate")).getFolderId());
%>
<html>
<head>
	<title>JSP for SysTeamForm form</title>
	<LINK href="css/default.css" rel=stylesheet>
	<LINK href="css/button.css" rel=stylesheet>
	<LINK href="css/main.css" type=text/css rel=stylesheet>
	<script type="text/javascript" src="js/dtree.js"></script>
<script type="text/javascript">
	function opchange(o){
		document.idaTemplateForm.method.value=o;
		document.idaTemplateForm.submit();
	}
	
	function configParam(m,p){
		document.idaTemplateForm.method.value=m;
		document.idaTemplateForm.paramName.value=p;
		document.idaTemplateForm.submit();
	}
	
	function selTemplate(tmptid){
		document.location.href = 'idaTemplate.do?method=sqlTemplate&templateId=' + tmptid;
	}
	
	var checkedbox=null;
	function changeTree(checkbox){
		if(checkbox.checked==true){
			if(checkedbox!=null && checkbox != checkedbox){
				checkedbox.checked=false;
				checkedbox=checkbox;
			}
			if(checkedbox==null){
				checkbox.checked=true;
				checkedbox=checkbox;
			}
		}
		else{
			if(checkedbox!=null){
				checkedbox.checked=false;
				checkedbox=null;
			}
		}
	}
	
	function showHiddenDiv(id){
		var divstyle=document.getElementById(id).style.display;
		if(divstyle=="none"){
			document.getElementById(id).style.display="";
		}else{
			document.getElementById(id).style.display="none";
		}
	}
</script>
</head>
<body>
<html:form action="/idaTemplate">
<table width="770" cellspacing="0" cellpadding="0" border="0" align="center">
<tbody>
	<tr>
		<td width="3" height="31">
			<img height="31" src="./images/table_01.gif" width="3" />
		</td>
		<td background="./images/table_02.gif" height="31">
			<table cellspacing="0" cellpadding="0" width="146" align="left" border="0">
				<tbody>
					<tr>
						<td width="51" background="./images/title_1_bg.gif">
							<img height="31" src="./images/title_1.gif" width="51" />
						</td>
						<td width="95" background="./images/title_1_bg.gif">
							<span class="color_b_666">条件参数模板</span>
						</td>
					</tr>
				</tbody>
			</table>
		</td>
		<td width="3">
			<img height="31" src="./images/table_03.gif" width="3" />
		</td>
	</tr>
	<tr>
		<td background="images/table_04.gif">
			<img height="5" src="images/table_04.gif" width="3">
		</td>
		<td style="PADDING-TOP: 3px" valign="top">
		<logic:notPresent name="idaTemplate" scope="request">
			<table width='100%' border='0' cellspacing='0' cellpadding='2'>
				<tr>
					<td width="100" align="center">选择模板：</td>
					<td align="left">
						<html:select property="idaTemplate.templateId" onchange="selTemplate(this.value);" value="${curTemplate.templateId}">
							<html:option value="">新建模板</html:option>
							<logic:present name="templateList" scope="request">
								<logic:iterate name="templateList" id="t">
									<logic:equal name="t" property="templateTypeId" value="30">
										<html:option value="${t.templateId}" >
											<bean:write name="t" property="templateName"/>
										</html:option>
									</logic:equal>
								</logic:iterate>
							</logic:present>
						</html:select>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">取数类别：</td>
					<td align="left">
						<html:select property="idaTemplate.anlsTypeId" value="${curTemplate.anlsTypeId}">
							<html:option value="10">用户&nbsp;&nbsp;</html:option>
							<html:option value="20">客户&nbsp;&nbsp;</html:option>
						</html:select>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">模板名称：</td>
					<td align="left">
						<html:text property="idaTemplate.templateName" size="90" value="${curTemplate.templateName}" />
					</td>
				</tr>
				<tr>
					<td width="100" align="center">模板描述：</td>
					<td align="left">
						<html:textarea property="idaTemplate.templateDesc" rows="3" cols="70" value="${curTemplate.templateDesc}" />
					</td>
				</tr>
				<tr>
					<td width="100" align="center">关联结果模板：</td>
					<td align="left">
						<html:select property="idaTemplate.resultTemplateId" value="${curTemplate.resultTemplateId}">
							<html:option value="">请选择</html:option>
							<logic:present name="templateList" scope="request">
								<logic:iterate name="templateList" id="t">
									<logic:equal name="t" property="templateTypeId" value="20">
										<html:option value="${t.templateId}" >
											<bean:write name="t" property="templateName"/>
										</html:option>
									</logic:equal>
								</logic:iterate>
							</logic:present>
						</html:select>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">选择文件夹：</td>
					<td align="left">
						<a href="javascript:showHiddenDiv('divTree');">请选择（单击可显示或隐藏选项）</a>
						<div style='display: none' id='divTree'>
							<script><%= TreeUtil.createIdaFolder("idaTemplate.folderId",foldId) %></script>
						</div>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">
						SQL语句：<br/><br/>
						（注：参数的格式按顺序用{1}、{2}...{n}引用）<br/><br/>
						<a href="" target="_blank">查看示例</a>
					</td>
					<td align="left">
						<html:textarea property="idaTemplate.sqlStmt" rows="10" cols="70" value="${curTemplate.sqlStmt}" />
					</td>
				</tr>
				<tr>
					<td width="100" align="center">号码类型：</td>
					<td align="left">
						<input type="radio" name="idaTemplate.nbrType" value="10" <logic:present name="curTemplate"><logic:equal name="curTemplate" property="nbrType" value="10">checked</logic:equal></logic:present> />电话号码
						<input type="radio" name="idaTemplate.nbrType" value="20" <logic:present name="curTemplate"><logic:equal name="curTemplate" property="nbrType" value="20">checked</logic:equal></logic:present> />产品实例号
						<input type="radio" name="idaTemplate.nbrType" value="30" <logic:present name="curTemplate"><logic:equal name="curTemplate" property="nbrType" value="30">checked</logic:equal></logic:present> />客户编号
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" class=btn_mouseout
							onmouseover="this.className=&#39;btn_mouseover&#39;"
							onmouseout="this.className=&#39;btn_mouseout&#39;"
							onmousedown="this.className=&#39;btn_mousedown&#39;"
							onmouseup="this.className=&#39;btn_mouseup&#39;" value="生成参数信息"
							onclick="opchange('buildSqlParam')">
					</td>
				</tr>
				<logic:present name="sqlParamList" scope="session">
				<tr>
					<td align="left" colspan="2">
						<table width='98%' border='0' cellspacing='1' cellpadding='2'>
							<tr align="center" height="25">
								<td background="images/atom_02.gif">参数名称</td>
								<td background="images/atom_02.gif">中文名称</td>
								<td background="images/atom_02.gif">关联业务原子</td>
								<td background="images/atom_02.gif">维表</td>
								<td background="images/atom_02.gif">列名称</td>
								<td background="images/atom_02.gif">显示列</td>
								<td background="images/atom_02.gif">排序</td>
								<td background="images/atom_02.gif">操作</td>
							</tr>
							<logic:iterate name="sqlParamList" id="p">
							<tr height="24">
								<td><bean:write name="p" property="paramName"/><bean:write name="p" property="dmnColumnName1"/></td>
								<td><bean:write name="p" property="paramNameCn"/></td>
								<td><bean:write name="p" property="bizAtomName"/></td>
								<td><bean:write name="p" property="dmnTableName"/></td>
								<td><bean:write name="p" property="dmnColumnName1"/></td>
								<td><bean:write name="p" property="dmnColumnName2"/></td>
								<td><bean:write name="p" property="displayId"/></td>
								<td><a href="javascript:configParam('configParam','<bean:write name="p" property="paramName"/>');">修改</a></td>
							</tr>
							</logic:iterate>
						</table>
					</td>
				</tr>
				</logic:present>
				<tr>
					<td align="center" colspan="2">
						<div align="center" id="commit">
							<img src='images/button_addnew.gif' width="63" height="21" onclick="opchange('insertTemplate')" />
							&nbsp;&nbsp;
							<img src='images/button_cancel.gif' width="63" height="21" onclick="opchange('sqlTemplate')" />
						</div>
					</td>
				</tr>
			</table>
		</logic:notPresent>
		
		<logic:present name="idaTemplate" scope="request">
			<table width='100%' border='0' cellspacing='' cellpadding='2'>
				<tr>
					<td width="100" align="center">选择模板：</td>
					<td align="left">
						<html:select property="idaTemplate.templateId" onchange="selTemplate(this.value);" value="${idaTemplate.templateId}">
							<html:option value="">新建模板</html:option>
							<logic:present name="templateList" scope="request">
								<logic:iterate name="templateList" id="t">
									<logic:equal name="t" property="templateTypeId" value="30">
										<html:option value="${t.templateId}" >
											<bean:write name="t" property="templateName"/>
										</html:option>
									</logic:equal>
								</logic:iterate>
							</logic:present>
						</html:select>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">取数类别：</td>
					<td align="left">
						<html:select property="idaTemplate.anlsTypeId" value="${idaTemplate.anlsTypeId}">
							<html:option value="10">用户&nbsp;&nbsp;</html:option>
							<html:option value="20">客户&nbsp;&nbsp;</html:option>
						</html:select>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">模板名称：</td>
					<td align="left">
						<html:text property="idaTemplate.templateName" value="${idaTemplate.templateName}" size="90" />
					</td>
				</tr>
				<tr>
					<td width="100" align="center">模板描述：</td>
					<td align="left">
						<html:textarea property="idaTemplate.templateDesc" value="${idaTemplate.templateDesc}" rows="3" cols="70" />
					</td>
				</tr>
				<tr>
					<td width="100" align="center">关联结果模板：</td>
					<td align="left">
						<html:select property="idaTemplate.resultTemplateId" value="${idaTemplate.resultTemplateId}">
							<html:option value="">请选择</html:option>
							<logic:present name="templateList" scope="request">
								<logic:iterate name="templateList" id="t">
									<logic:equal name="t" property="templateTypeId" value="20">
										<html:option value="${t.templateId}" >
											<bean:write name="t" property="templateName"/>
										</html:option>
									</logic:equal>
								</logic:iterate>
							</logic:present>
						</html:select>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">选择文件夹：</td>
					<td align="left">
						<a href="javascript:showHiddenDiv('divTree');">请选择（单击可显示或隐藏选项）</a>
						<div style='display: none' id='divTree'>
							<script><%= TreeUtil.createIdaFolder("idaTemplate.folderId",foldId) %></script>
						</div>
					</td>
				</tr>
				<tr>
					<td width="100" align="center">
						SQL语句：<br/><br/>
						（注：参数的格式按顺序用{1}、{2}...{n}引用）<br/><br/>
						<a href="" target="_blank">查看示例</a>
					</td>
					<td align="left">
						<html:textarea property="idaTemplate.sqlStmt" value="${idaTemplate.sqlStmt}" rows="10" cols="70" />
					</td>
				</tr>
				<tr>
					<td width="100" align="center">号码类型：</td>
					<td align="left">
						<input type="radio" name="idaTemplate.nbrType" value="10" <logic:equal name="idaTemplate" property="nbrType" value="10">checked</logic:equal> />电话号码
						<input type="radio" name="idaTemplate.nbrType" value="20" <logic:equal name="idaTemplate" property="nbrType" value="20">checked</logic:equal> />产品实例号
						<input type="radio" name="idaTemplate.nbrType" value="30" <logic:equal name="idaTemplate" property="nbrType" value="30">checked</logic:equal> />客户编号
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="button" class=btn_mouseout
							onmouseover="this.className=&#39;btn_mouseover&#39;"
							onmouseout="this.className=&#39;btn_mouseout&#39;"
							onmousedown="this.className=&#39;btn_mousedown&#39;"
							onmouseup="this.className=&#39;btn_mouseup&#39;" value="生成参数信息"
							onclick="opchange('buildSqlParam')">
					</td>
				</tr>
				<logic:present name="sqlParamList" scope="session">
				<tr>
					<td align="left" colspan="2">
						<table width='98%' border='0' cellspacing='1' cellpadding='2'>
							<tr align="center" height="25">
								<td background="images/atom_02.gif">参数名称</td>
								<td background="images/atom_02.gif">中文名称</td>
								<td background="images/atom_02.gif">关联业务原子</td>
								<td background="images/atom_02.gif">维表</td>
								<td background="images/atom_02.gif">列名称</td>
								<td background="images/atom_02.gif">显示列</td>
								<td background="images/atom_02.gif">排序</td>
								<td background="images/atom_02.gif">操作</td>
							</tr>
							<logic:iterate name="sqlParamList" id="p">
							<tr height="24">
								<td><bean:write name="p" property="paramName"/><bean:write name="p" property="dmnColumnName1"/></td>
								<td><bean:write name="p" property="paramNameCn"/></td>
								<td><bean:write name="p" property="bizAtomName"/></td>
								<td><bean:write name="p" property="dmnTableName"/></td>
								<td><bean:write name="p" property="dmnColumnName1"/></td>
								<td><bean:write name="p" property="dmnColumnName2"/></td>
								<td><bean:write name="p" property="displayId"/></td>
								<td><a href="javascript:configParam('configParam','<bean:write name="p" property="paramName"/>');">修改</a></td>
							</tr>
							</logic:iterate>
						</table>
					</td>
				</tr>
				</logic:present>
				<tr>
					<td align="center" colspan="2">
						<div align="center" id="commit">
							<img src='images/button_modify.gif' width="63" height="21" onclick="opchange('updateTemplate')" />
							&nbsp;&nbsp;
							<img src='images/button_delete.gif' width="63" height="21" onclick="opchange('deleteTemplate')" />
							&nbsp;&nbsp;
							<img src='images/button_exit.gif' width="63" height="21" onclick="opchange('sqlTemplate')" />
						</div>
					</td>
				</tr>
			</table>
		</logic:present>
		</td>
		<td background="images/table_05.gif">
			<img height="5" src="images/table_05.gif" width="3">
		</td>
	</tr>
	<tr height="3">
		<td height="3">
			<img height="12" src="images/table_06.gif" width="3">
		</td>
		<td height="3">
			<img height="3" src="images/table_07.gif" width="764">
		</td>
		<td height="3">
			<img height="12" src="images/table_08.gif" width="3">
		</td>
	</tr>
</tbody>
</table>
<br />
<html:hidden property="method" value="sqlTemplate" />
<html:hidden property="paramName" value="" />
<html:hidden property="idaTemplate.templateTypeId" value="30" />
<html:hidden property="idaTemplate.latnId" value="${Latn_Id}" />
</html:form>
<% session.removeAttribute("curTemplate"); %>
</body>
</html>

